<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content">
  <div class="top">
    <div class="center">
      <h1><?php echo $heading_title; ?></h1>
    </div>
  </div>
  <div class="middle">
  <form action="" method="post" enctype="multipart/form-data" id="site_form">
 
    <div class="product-filter" >
        <a id="change_category" class="button" onclick="$('#site_form').submit();"><span>转移目录</span></a>
        <div class="sort">
        按目录查看:<select id="cat_id" name="cat_id" onchange="location = 'index.php?route=site/list&cat_id=' + this.value;"><?php echo $opt_category; ?></select>   
        <!-- 排序:<select id="sort" name="sort" onchange="location = this.value;"> -->
        </div>
    </div>
    
    <table class="list">
      <thead>
        <tr>
        <td class="left"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
        <td class="left">编号</td>
        <td class="left">站点Url</td>
        <td class="left">站点名称</td>
        <td class="left">PageRank</td>
        <td class="left">目录</td>
        <td class="left">账号</td>
        <td class="left">备注</td>
        <td class="left">操作</td>
        </tr>
      </thead>
      <tbody>
      <?php if ($sites) { ?>
    <?php foreach ($sites as $site) { ?>
   <tr id="site_list_<?php echo $site['id']; ?>">
        <td class="left"><?php if ($site['selected']) { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $site['id']; ?>" checked="checked" />
                <?php } else { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $site['id']; ?>" />
                <?php } ?></td>
          <td class="left"><?php echo $site['id']; ?></td>
        <td class="left"><?php echo $site['url']; ?></td>
        <td class="right"><?php echo $site['name']; ?></td>
        <td class="right" id="site_pr_<?php echo $site['id']; ?>"><?php echo $site['pagerank']; ?></td>
        <td class="right"><?php echo $site['cat_name']; ?></td>
        <td class="right"><?php echo $site['account']; ?></td>
        <td class="right"><?php echo $site['other']; ?></td>
        <td class="center">[<a href="javascript:void(0);" class="update_site_info" name="update_site_info" rel="<?php echo $site['id'];?>">更新</a>][<a href="index.php?route=site/manger/edit&site_id=<?php echo $site['id']; ?>">编辑</a>][<a href="javascript:void(0);" class="delete_site" name="delete_site" rel="<?php echo $site['id'];?>">删除</a>]</td>
    </tr>
    <?php } ?>
    <?php } else { ?>
        <tr><td class="center" colspan="10"><?php echo $text_empty; ?></td></tr>
        <?php } ?>
    </tbody>
    </table>
<div class="pagination"><?php echo $pagination; ?></div>
  </div>
  <div class="bottom">
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>
  </div>
</div>
<script language="javascript">
    $(document).ready(function(){
        
        /* 更新PR值 */
        $(".update_site_info").each(function(){
            $(this).click(function(){
                    var site_id = $(this).attr("rel");
                    var old_pagerank = $("#site_pr_"+site_id).html();
                    $('.success, .warning, .attention, .information, .wait').remove(); 
                    $("#site_pr_"+site_id).html('<div class="wait"><img src="home/view/image/ajax_load.gif" alt="加载中" class="wait" /></div>').show();
                    $.ajax({
                    url: 'index.php?route=site/manger/getPageRank' + '&site_id=' + site_id +'',
                    dataType: 'json',
                    success: function(json) 
                    {
                        if (json['pagerank']) {
                            var pagerank = json['pagerank'] ; 
                            $.ajax({
                                url: 'index.php?route=site/manger/updatePageRank',
                                type:'POST',
                                data : 'site_id=' + site_id + '&pagerank=' + pagerank,
                                dataType: 'json',
                                success: function(json) 
                                {
                                    if (json['success']) 
                                    {
                                        $("#site_pr_"+site_id).html(pagerank);
                                        $('.success, .warning, .attention, .information').remove();
                                        $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
                                        $('.success').fadeIn('slow');
                                        $('html, body').animate({ scrollTop: 0 }, 'slow'); 
                                    }
                                }
                            }); 
                        }
                        if(json['error']){
                            $('.success, .warning, .attention, .information, .wait').remove(); 
                            $("#site_pr_"+site_id).html(old_pagerank);
                            $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
                            $('.warning').fadeIn('slow');
                            $('html, body').animate({ scrollTop: 0 }, 'slow'); 
                        }
                    }
                })
            })
        });
        
        /* 删除站点 */
        $('.delete_site').each(function(){
            $(this).click(function(){
                var site_id = $(this).attr("rel");
                if(confirm('确定要删除？'))
                {
                    $.ajax({
                        url: 'index.php?route=site/manger/delete',
                        type:'POST',
                        data : 'site_id=' + site_id,
                        dataType: 'json',
                        success: function(json) 
                        {
                            if (json['success']) 
                            {
                                $('.success, .warning, .attention, .information').remove();
                                $('#site_list_'+site_id).remove();
                                $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
                                $('.success').fadeIn('slow');
                                $('html, body').animate({ scrollTop: 0 }, 'slow'); 
                            }
                        }
                    });
                }
            })
        });
        
        /* 批量转移网站目录 */
        $("#site_form").submit(function(){
            var options = {
                    url:        "index.php?route=site/manger/move",
                    dataType:        "json",
                    //beforeSubmit:  wait,   
                    success:       showResponse 
            };
            jQuery(this).ajaxSubmit(options);
            return false;
        });
    });
    
    function showResponse(data)
    {
        
        $('.success, .warning, .wait').remove();
        if(data['error'])
        {
            $('#notification').html('<div class="warning" style="display: none;">' + data['error']['warning'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
            $('.warning').fadeIn('slow');
            return false;
        }
        
        if(data['selected'])
        {
            $.ajax({
                url: 'index.php?route=site/manger/changeCategory',
                type:'POST',
                data : 'selected=' + data['selected'] + '&cat_id=' + cat_id,
                dataType: 'json',
                success: function(json) {
                    if (json['success']) {
                            $('.success, .warning, .attention, .information').remove();
                            $('#notification').html('<div class="warning" style="display: none;">' + json['success'] + '<img src="home/view/image/close.png" alt="" class="close" /></div>');
                            $('.warning').fadeIn('slow');
                            $('html, body').animate({ scrollTop: 0 }, 'slow'); 
                        }
                    }
            }); 
        }
    }
</script>
<?php echo $footer; ?> 